var config = require('../../../config.js');
var common = require('../../utils/common.js');
var promise=require('../../utils/es6-promise.auto.min.js');
var util=require('../../utils/util.js');
function load_page(data, currentPage, tab_tab_list,name, page) {
  wx.request({
    url: config.materials + '/search/findBySeriesId',
    data: data,
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var data = res.data;
      var templist = tab_tab_list.list;
      var materials = data._embedded.materials;
      var obj = {};//申明一个对象，
      obj.count = 0;
      var len = materials.length;
      new promise(function (resolve, reject) {
        for (var i = 0; i < materials.length; i++) {
          var foramt = util.formateDate(materials[i].showTime);
          materials[i].showTime = foramt;
          materials[i].day = util.getDays(materials[i].showTime);
          //common.findFavorer_a(name, materials[i],obj);
          materials[i].bindtap = "inplay";

          var date = new Date(foramt);
          materials[i].hour = date.getFullYear();

          materials[i].minutes = (date.getMonth() + 1) > 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
          materials[i].seconds = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
        }
        resolve(materials);
      }).then(function (materials){
        //接口获取 收藏
        templist = templist.concat(materials);
        tab_tab_list.list = templist;
        tab_tab_list.page = currentPage;

        page.setData({
          list: templist
        });
      });
     
    }
  });
}

function load_list(data, currentPage, tab_tab_list,name, page) {
  wx.request({
    url: config.materials + '/search/findBySeriesId',
    data: data,
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var data = res.data;
      var materials = data._embedded.materials;

      var obj = {};//申明一个对象，
      obj.count = 0;
      var len = materials.length;
      new promise(function (resolve, reject) {
        for (var i = 0; i < materials.length; i++) {
          var foramt = util.formateDate(materials[i].showTime);
            materials[i].showTime =foramt;
          materials[i].day = util.getDays(materials[i].showTime);
         // common.findFavorer_a(name, materials[i],obj);
          materials[i].bindtap="inplay";

          var date = new Date(foramt);
          materials[i].hour = date.getFullYear();
       
          materials[i].minutes = (date.getMonth() + 1) > 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1);
          materials[i].seconds = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
        }
        resolve(materials);
      }).then(function (materials){
        //接口获取 收藏
        var templist = materials;
        tab_tab_list.list = templist;
        tab_tab_list.page = currentPage;
        tab_tab_list.pageSize = data.page.totalPages;
        page.setData({
          list: templist
        });
      });  
    }
  });
}
module.exports = {
  load_page: load_page,
  load_list: load_list
}